import java.util.Arrays;

public class Trangle {
    public int test(int[] elem){
        Arrays.sort(elem);
        int left = 0;
        int right = elem.length - 1;
        int Index = right - 1;
        int trangle = 0;

        while (right >= 2){
            while (left < Index){
                if (elem[left] + elem[Index] > elem[right]){
                    trangle += Index - left;
                    Index--;
                }else {
                    left++;
                }
            }
            right--;
            Index = right - 1;
            left = 0;
        }
        return trangle;
    }
}
